//
//  NewCarViewController.m
//  A段项目
//
//  Created by cmcmhjr123 on 15/7/20.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "NewCarViewController.h"
#import "BaseHeader.h"
#import "SANetWorkingTask.h"
#import "SellRankTableViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "SellRankTableViewCell.h"
#import "newModel.h"


@interface NewCarViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic, retain) NSMutableArray *tableArr;
@property (nonatomic, retain) UITableView *tab;

@end

@implementation NewCarViewController

- (void)dealloc
{
    [super dealloc];
    
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.tableArr = [NSMutableArray array];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"新车上市";
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"]  style:UIBarButtonItemStyleDone target:self action:@selector(leftAction:)];
    self.navigationItem.leftBarButtonItem= bar;

    
    self.tab = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth) style:UITableViewStylePlain];
    
    _tab.dataSource = self;
    _tab.delegate = self;
    _tab.rowHeight = 80;
    [_tab registerClass:[SellRankTableViewCell class] forCellReuseIdentifier:@"a"];
    
    [self.view addSubview:_tab];
    
     [SANetWorkingTask request:@"http://api.ycapp.yiche.com/car/GetSerialInfoForNew" parmater:nil block:^(NSDictionary *result) {
         NSArray *arr = [result objectForKey:@"data"];
         for (NSDictionary *dic in arr) {
             newModel *model = [[newModel alloc] init];
             [model setValuesForKeysWithDictionary:dic];
             [self.tableArr addObject:model];
         }
         [self.tab reloadData];
     }];

}

- (void)leftAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.tableArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SellRankTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"a"];
    
    newModel *model = [self.tableArr objectAtIndex:indexPath.row];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:model.Img] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    
    
    cell.carname.text = model.ShowName;

    cell.minlabel.text = model.Price;
  
  
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
